package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuInfoDetailFeignClient;
import com.atguigu.gmall.item.vo.SkuInfoDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class ItemController {

    @Autowired
    private SkuInfoDetailFeignClient skuInfoDetailFeignClient ;

    @GetMapping(value = "/{skuId}.html")
    public String item(@PathVariable(value = "skuId") Long skuId , Model model) {

        // 发送远程调用获取数据
        Result<SkuInfoDetailVo> result = skuInfoDetailFeignClient.findBySkuId(skuId);
        SkuInfoDetailVo skuInfoDetailVo = result.getData();

        // 把数据存储到Model数据模型中
        model.addAttribute("categoryView" , skuInfoDetailVo.getCategoryView()) ;
        model.addAttribute("skuInfo" , skuInfoDetailVo.getSkuInfo()) ;
        model.addAttribute("price" , skuInfoDetailVo.getPrice()) ;
        model.addAttribute("spuSaleAttrList" , skuInfoDetailVo.getSpuSaleAttrList()) ;
        model.addAttribute("valuesSkuJson" , skuInfoDetailVo.getValuesSkuJson()) ;

        // 跳转页面
        return "item/index" ;
    }

}
